/*
 * @(#)DataOper.java 
 *
 * Project: BUS
 *
 * Modify Information:
 * =============================================================================
 *   Author       Date       Description
 *   vincent     2006-03-06   first release  
 *   ------------ ---------- ---------------------------------------------------
 *
 * Copyright Notice:
 * =============================================================================
 *    Copyright (c) 2001-2005 Beijing HiTRUST Technology Co., Ltd. 1808 Room, 
 *        Science & Technology Building, No. 9 South Street, Zhong Guan Cun, 
 *        Haidian District, Beijing ,100081, China All rights reserved.
 *
 *    This software is the confidential and proprietary information of
 *        Beijing HiTRUST Technology Co., Ltd. ("Confidential Information").
 *        You shall not disclose such Confidential Information and shall use it
 *        only in accordance with the terms of the license agreement you entered
 *        into with HiTRUST.
 *
 * Warning:
 * =============================================================================
 */
package com.hitrust.gs.lib.db.backup;

import com.hitrust.gs.lib.GSLogWriter;

public class DataOper {

	/**
	 * 操作外部命令的方法
	 * @param aCmdExpStr 命令行代码
	 * @return	0 成功  1 失败
	 * @throws Exception
	 */
	public int dataFunction(String aCmdExpStr) throws Exception {
		
		Runtime tRuntime = Runtime.getRuntime();
		Process expPr = tRuntime.exec(aCmdExpStr);
		
		// 控制Process的所有输入和输出
		StreamGobbler tErrorGobbler = new StreamGobbler(expPr.getErrorStream(),
				"ERROR");

		StreamGobbler tOutputGobbler = new StreamGobbler(expPr.getInputStream(),
				"OUTPUT");

		tErrorGobbler.start();
		tOutputGobbler.start();

		//外部命令返回的状态
		int tExitVal = expPr.waitFor();
		GSLogWriter.info("ExitValue: " + tExitVal);
		return tExitVal;
	}
}
